require.config({
    paths: {
        'jquery': ['http://cdn.bootcss.com/jquery/2.2.4/jquery.min', '/js/lib/jquery.min'],
        'doT': '/js/lib/doT.min',
        'bootstrap': '/js/lib/bootstrap.min',
        'datetimepicker': '/js/lib/bootstrap-datetimepicker.min',
        'select2': '/js/lib/select2.min'
    }
});

require(['jquery'], function($) {
    $(function() {
        $('.toggleUl').on('click', function(e) {
            $(e.currentTarget).children('ul').slideToggle();
        });

        function activeSidebar() {
            var href = window.location.href;
            var sidebarItems = $('.sidebar').find('li');
            console.log();
            for (var i = 0; i < sidebarItems.length; i++) {
                var itemHref = $(sidebarItems[i]).children('a').attr('href');
                if (href.indexOf(itemHref) != -1 && itemHref) {
                    $(sidebarItems[i]).children('a').css('color', '#46a3ff');
                    $(sidebarItems[i]).parent().show();
                }
            }
        }

        activeSidebar();

        $('.logout').on('click', function(event) {
            sessionStorage.clear();
            $('#confirmMsg').html('确定要注销吗?');
            $('#confirmBtn').on('click', function(event) {
                location.href = '/views/login.html';
            });
            $('#confirmModal').modal('show');
        });

        function checkLogin() {
            if (!sessionStorage.getItem('token')) {
                window.location.href = '/views/login.html';
            }
        }
        checkLogin();

        function initName() {
            $('#name').text(sessionStorage.getItem('name'));
            if (sessionStorage.getItem('role') == 1) {
                $('#role').text('管理员');
            } else{
                $('#role').text('堂主');
            }
        }
        initName();
    });

});
